package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/30 17:30
 **/
public class Day45_12_Offer18_DeleteNode {
    class Solution {
        public ListNode deleteNode(ListNode head, int val) {
            ListNode dummyHead = new ListNode(-1);
            ListNode pre = dummyHead;
            pre.next = head;
            while(pre.next.val != val) pre = pre.next;
            pre.next = pre.next.next;
            return dummyHead.next;
        }
    }
    class Solution2 {
        public ListNode deleteNode(ListNode head, int val) {
            if(head == null) return null;
            if(head.val == val) return head.next;
            head.next = deleteNode(head.next,val);
            return head;
        }
    }
}